package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;
import java.util.Arrays;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.AppVersion;
import com.ruoyi.business.service.IAppVersionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * App版本Controller
 *
 * @author Eric
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/business/version")
public class AppVersionController extends BaseController {
    @Resource
    private IAppVersionService appVersionService;

    /**
     * 查询App版本列表
     */
    @PreAuthorize("@ss.hasPermi('business:version:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppVersion appVersion) {
        startPage();
        List<AppVersion> list = appVersionService.list(Wrappers.lambdaQuery(AppVersion. class).
        setEntity( appVersion));
        return getDataTable(list);
    }

    /**
     * 导出App版本列表
     */
    @PreAuthorize("@ss.hasPermi('business:version:export')")
    @Log(title = "App版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppVersion appVersion) {
        List<AppVersion> list = appVersionService.list(Wrappers.lambdaQuery(AppVersion. class).
        setEntity( appVersion));
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion. class);
        util.exportExcel(response, list, "App版本数据");
    }

    /**
     * 获取App版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:version:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appVersionService.getById(id));
    }

    /**
     * 新增App版本
     */
    @PreAuthorize("@ss.hasPermi('business:version:add')")
    @Log(title = "App版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppVersion appVersion) {
        return toAjax(appVersionService.save(appVersion));
    }

    /**
     * 修改App版本
     */
    @PreAuthorize("@ss.hasPermi('business:version:edit')")
    @Log(title = "App版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppVersion appVersion) {
        return toAjax(appVersionService.updateById(appVersion));
    }

    /**
     * 删除App版本
     */
    @PreAuthorize("@ss.hasPermi('business:version:remove')")
    @Log(title = "App版本", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appVersionService.removeBatchByIds(Arrays.asList(ids)));
    }
}
